package com.kehao.newcoder;

import org.junit.Test;

public class NC17Solution {
    public int getLongestPalindrome (String A) {
        if(A.length()==0) return 0;
        int result = 1;
        char[] charArray = A.toCharArray();
        int[][] dp =new int[charArray.length][charArray.length];
        for (int i = 0; i < charArray.length; i++) {
            dp[i][i] = 1;
        }
        for (int dis = 1; dis < charArray.length; dis++) {
            for (int i = 0; i+dis < charArray.length; i++) {
                if(dp[i+1][i+dis-1] ==-1){
                    dp[i][i+dis] = -1;
                    continue;
                }
                dp[i][i+dis] = charArray[i]==charArray[i+dis]?dp[i+1][i+dis-1]+2:-1;
                if(result<dp[i][i+dis]){
                    result = dp[i][i+dis];
                }
            }
        }
        return result;
    }

    @Test
    public void test01(){
        int result = getLongestPalindrome("babcbcacababb");
        System.out.println(result);
    }
}
